import { ecgMin, xkEcgTp } from '@/service/config/servicePort'
import { http } from '@/utils/http'
import { getEnvBaseUrl } from '@/utils'

interface params {
  [key: string]: any
}

/** GET 请求 */
// 获取诊断结果
export const getPdf = (id: string) => {
  return getEnvBaseUrl() + xkEcgTp + '/getPdf/' + id
}
// 获取小程序openid
export const jscode_session = (params?: params) => {
  return http.get<params>(ecgMin + '/sns/jscode2session', params)
}
// 获取小程序token
export const token = (params?: params) => {
  return http.get<params>(ecgMin + '/cgi-bin/token', params)
}

/** POST 请求 */
// 获取用户信息
export const login = (params?: params) => {
  return http.post<params>(ecgMin + '/login', params)
}
// 获取已绑定设备
export const getDevices = (params: { userId: string }) => {
  return http.post<params>(ecgMin + '/getDevices', params)
}
// 解除绑定
export const unbindDevice = (params: { userId: string; sn: string }) => {
  return http.post<params>(ecgMin + '/unbindDevice', params)
}
// 绑定设备
export const bindDevice = (params: {
  userId: string
  sn: string
  deviceName?: string
  deviceType?: string
}) => {
  return http.post<params>(ecgMin + '/bindDevice', params)
}
// 获取绑定状态
export const getDeviceStatus = (params: { sn: string }) => {
  return http.post<params>(ecgMin + '/getDeviceStatus', params)
}
// 获取诊断列表
export const getReportList = (params: {
  userId: string
  pageNum?: number
  pageSize?: number
  status?: number
  startTime: string
  endTime: string
}) => {
  return http.post<params>(ecgMin + '/getReportList', params)
}
// 获取个人资料
export const getUserInfo = (params: { userId: string }) => {
  return http.post<params>(ecgMin + '/getUserInfo', params)
}
// 保存个人资料
export const saveUserInfo = (params: params) => {
  return http.post<params>(ecgMin + '/saveUserInfo', params)
}
// 保存预约登记
export const registerData = (params: params) => {
  return http.post<params>(ecgMin + '/registerData', params)
}
// 开启监测
export const startMonitor = (params: { userId: string; sn: string }) => {
  return http.post<params>(ecgMin + '/startMonitor', params)
}
// 结束监测
export const stopMonitor = (params: { userId: string; sn: string }) => {
  return http.post<params>(ecgMin + '/stopMonitor', params)
}
// 获取检查单状态
export const getExamStatus = (params: { examId: string }) => {
  return http.post<params>(ecgMin + '/getExamStatus', params)
}
// 查询ecg状态
export const queryEcgMsg = (params: { sn: string }) => {
  return http.post<params>(ecgMin + '/queryEcgMsg', params)
}
// 获取小程序phoneNumber
export const getuserphonenumber = (params: {
  access_token: string
  openid: string
  code: string
}) => {
  return http.post<params>(
    ecgMin + `/wxa/business/getuserphonenumber?access_token=${params.access_token}`,
    { openid: params.openid, code: params.code },
    null,
    { separate: true },
  )
}
// 获取电量
export const getDeviceElectric = (params: { sn: string }) => {
  return http.post<params>(ecgMin + '/getDeviceElectric', params)
}
// 订阅模板
export const saveTemplateId = (params: { userId: string; templateId?: string }) => {
  return http.post<params>(ecgMin + '/saveTemplateId', params)
}

// 上传头像
export const saveAvatar = (params: { userId: string; templateId?: string }) => {
  return http.post<params>(ecgMin + '/saveAvatar', params)
}
